package cn.edu.ctbu.dp2.api;

import cn.edu.ctbu.dp2.entity.Teacher;
import cn.edu.ctbu.dp2.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/teacher")
public class TeacherApiController {

    @Autowired
    private TeacherService teacherService;
    @GetMapping("/list")
    public List<Teacher>  findAll(){
        List<Teacher>teachers=teacherService.getAll();
        return teachers;
    }


    @GetMapping("/{id}")
    public Teacher  findById(@PathVariable int id){
        Teacher teacher=teacherService.findById(id);
        return teacher;
    }
    /**
     * 增加老师
     * @param teacher
     * @return
     */
    @PostMapping("/add")
    public Teacher add(Teacher teacher) {
        return teacherService.add(teacher);
    }
    /**
     * 更新老师信息
     * @param teacher
     * @return
     */
    @PutMapping("/update")
    public Teacher update(Teacher teacher) {
        return teacherService.update(teacher);
    }
    /**
     * 删除学生信息
     * @param id
     */
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable Integer id) {
        teacherService.delete(id);
    }
}
